package background;

import android.os.AsyncTask;
import database.FTodoEntities;
import entity.DummyDeleteTask;
import entity.FTodo;

public class DeleteTaskAsyn extends AsyncTask<DummyDeleteTask, Void, DummyDeleteTask> {

	@Override
	protected DummyDeleteTask doInBackground(DummyDeleteTask... arg0) {
		
		/*boolean result = false;
		DummyDeleteTask delete = arg0[0];
		FTodoEntities entity = new FTodoEntities(delete.context);
		if(delete.adapter != null){
			FTodo ftodo = (FTodo)delete.adapter.getItem(delete.childPosition);
			result = entity.deleteFTodo(ftodo.id);
		}else if(delete.adapter2 != null){
			FTodo ftodo = (FTodo)delete.adapter2.getChild(delete.groupPosition, delete.childPosition);
			result = entity.deleteFTodo(ftodo.id);			
		}
		if(result)
			return delete;*/
		return null;
	}
	
	@Override
	protected void onPostExecute(DummyDeleteTask result) {
		
		if(result != null){
			if(result.adapter != null){
				result.adapter.mFTodos.get(result.groupPosition).remove(result.childPosition);
				if(result.adapter.mFTodos.get(result.groupPosition).size() <= 0){
					result.adapter.mFTodos.remove(result.groupPosition);
					result.adapter.mGroups.remove(result.groupPosition);
				}
				result.adapter.notifyDataSetChanged();
			}else if(result.adapter2 != null){
				result.adapter2.mFTodos.remove(result.childPosition);
				result.adapter2.notifyDataSetChanged();
			}
		}
	}
}
